'use strict';
/**
 * @bussiness {商品}
 * @author {填写作者}
 * @date {创建时间}
 * **/
 const Service = require('egg').Service;
 class Goods extends Service {
    /**@effect {拿取主页商品信息数据}**/
    async homeGoods(){
        const {app} = this;
        const res = await app.mysql.select('goods'); // 拿到全部商品数据
        return res;
    }
    /**@effect {拿取所有商品信息数据}**/
    async allGoods(params){
        const {app} = this;
        const {limit, offset} = params; /**@params {limit:数量, offset:偏移量}**/
        const res = await app.mysql.select('goods', {limit:limit,offset:offset});
        return res;
    }
     /**
     * @effect {拿取搜索或者选择商品分类拿到信息数据}   
     * @params {category:分类, name:商品名, keyword:关键词}
     * @keywords {前端传进来参数统一名字为keywords}
    **/
    async takeGoodsList(params){
        const {app} = this;
        const {keywords, limit, offset} = params;
        const res = await app.mysql.select('goods', { /**分类查询**/where:{goods_tags: keywords},
            limit:limit, offset:offset
        })
        return res
    }
         /**
     * @effect {拿取搜索或者选择商品分类拿到信息数据}   
     * @params {id，商品id}
     * @id {前端传进来参数统一名字为goods_id}
    **/
   async takeGoodsById(params) {
        const {app} = this;
        const {id} = params;
        const res = await app.mysql.get('goods', {goods_id:id});
        return res
   }
 }
 module.exports = Goods